﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace Pampa.MVC.Controllers
{
    public abstract class AbstractController : Controller
    {
        protected JsonResult BuildResponse(Func<object> action)
        {
            try
            {
                var result = action.Invoke();
                return Json(new { value = result });
            }
            catch (Exception ex)
            {
                return Json(new { error = ex.Message });
            }
        }

        protected JsonResult BuildResponse(Action action)
        {
            try
            {
                action.Invoke();
                return Json(new { });
            }
            catch (Exception ex)
            {
                return Json(new { error = ex.Message });
            }
        }
    }
}
